package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.jasper.tagplugins.jstl.core.Out;

import daoImpl.UserDaoImpl;

/**
 * Servlet implementation class LoginServlet
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	/**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }


	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	UserDaoImpl userImpl = new UserDaoImpl();
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/xml;charset=UTF-8");
		PrintWriter out=resp.getWriter();
		StringBuilder builder = new StringBuilder();
		String name=req.getParameter("username");
		builder.append("<message>");
		if(name==null||name.length()==0){
			builder.append("用户名不能为空");
		}else{		
		System.out.println(name);
		boolean res=userImpl.login(name);
		if (res) {	
			 builder.append("用户名[" + name + "]输入正确");
			System.out.println("登录成功----------");
		}else {
			System.out.println("用户不存在！");
			 builder.append("----用户名[" + name + "] 不已经存在");
		}
		builder.append("</message>");
		}
		out.write(builder.toString());
	}
}
